package com.sx.manage.service.company;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.sx.model.constants.MDataStatusType;
import com.sx.model.manage.mybatis.form.company.MCompanyMessageInfoEntityForm;
import com.sx.model.manage.mybatis.vo.company.MCompanyMessageInfoVO;
import com.sx.model.manage.mybatis.vo.consumer.login.MConsumerLoginVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;
import com.sx.model.manage.mybatis.vo.result.ResultObjectVO;

@Service("mCompanyMessageWebServiceImpl")
public class MCompanyMessageWebServiceImpl {
	private Logger log = LoggerFactory.getLogger(this.getClass());

	@Resource(name = "mCompanyMessageInfoServiceImpl")
	private IMCompanyMessageInfoService mCompanyMessageInfoServiceImpl;
	
	/** 新增消息**/
	public ResultBooleanVO message_add(MCompanyMessageInfoEntityForm form,MConsumerLoginVO loginConsumerVO){
		
		if(null == form.getCompany_id()){
			log.info("新增公司消息失败，公司id为空form={}",form);
			return new ResultBooleanVO(false,null,"请选择需要配置的公司");
		}		
		log.debug("公司发薪通知消息新增");
		ResultObjectVO<MCompanyMessageInfoVO> objResult = mCompanyMessageInfoServiceImpl.search_company_id(form);
		if( !objResult.isSuccess()){
			log.error("查询消息出错，返回");
			return new ResultBooleanVO(false,null,objResult.getMsg());
		}
		
		if( null !=objResult.getObjVo() && form.getCompany_id().equals(objResult.getObjVo().getCompany_id())){
			log.info("公司已经配置了消息，不需要重复配置companyId={}",form.getCompany_id());
			return new ResultBooleanVO(false,null,"公司已经配置了消息，不需要重复配置。");
		}
		return mCompanyMessageInfoServiceImpl.add_companyMessage(form, loginConsumerVO);
	}
	
	/**查询分页 **/
	public ResultListVO<MCompanyMessageInfoVO> queryPage(MCompanyMessageInfoEntityForm form){
		log.info("查询公司发薪通知消息分页信息form={}",form);
		return mCompanyMessageInfoServiceImpl.search_companyMessage(form);
	}
	
	/** 启用**/
	public ResultBooleanVO enable(Long id,MConsumerLoginVO loginConsumerVO){
		if( null == id){
			log.info("启用公司发薪设置参数为空id={}",id);
			return new ResultBooleanVO("m.parameter.is.null");
		}
		
		MCompanyMessageInfoEntityForm form = new MCompanyMessageInfoEntityForm();
		                              form.setId(id);		
		                              form.setPayroll_message_status(MDataStatusType.DATA_AVAILABLE);
		log.info("启用公司发薪设置参数为空form={}",form);
		return mCompanyMessageInfoServiceImpl.edit_companyMessage(form, loginConsumerVO);
	}
	
	/** 停用**/
	public ResultBooleanVO disable(Long id,MConsumerLoginVO loginConsumerVO){
		if( null == id){
			log.info("停用公司发薪设置参数为空id={}",id);
			return new ResultBooleanVO("m.parameter.is.null");
		}
		
		MCompanyMessageInfoEntityForm form = new MCompanyMessageInfoEntityForm();
								        form.setId(id);		
								        form.setPayroll_message_status(MDataStatusType.DATA_DISABLE);
		log.info("启用公司发薪设置参数为空form={}",form);
		return mCompanyMessageInfoServiceImpl.edit_companyMessage(form, loginConsumerVO);
	}
}
